﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using EnterApp.Core.DomainModel;
using EnterApp.Core.Extensions;

namespace EnterApp.Repository.EF
{
    public class BaseDataContext : DbContext
    {

        public virtual new IDbSet<TEntity> Set<TEntity>() where TEntity : AggregateRoot<UniqueId>
        {
            return base.Set<TEntity>();
        }

        public virtual void Add<TEntity>(TEntity entity)
            where TEntity : AggregateRoot<UniqueId>
        {
            Set<TEntity>().Add(entity);
        }

        public virtual void Remove<TEntity>(TEntity entity)
            where TEntity : AggregateRoot<UniqueId>
        {
            Set<TEntity>().Remove(entity);
        }

        public virtual void Remove<TEntity>(IEnumerable<TEntity> entities)
            where TEntity : AggregateRoot<UniqueId>
        {
            entities.ForEach(entity => Set<TEntity>().Remove(entity));
        }

        public virtual void Commit()
        {
            SaveChanges();
        }
    }
}
